﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.Composition;
using Core.DataAccess.IRepositories;

namespace Core.DataAccess.Repositories
{
    [Export(typeof(IFolderImgCoverRepository))]
    public class FolderImgCoverRepository : IFolderImgCoverRepository
    {
        private Connection conn;

        public FolderImgCoverRepository()
        {
            conn = new Connection();
        }

        public FolderImgCover GetFolderImgCoverByAccountID(int accountID)
        {
            using (MXHEntities context = conn.GetContext())
            {
                var item = from fol in context.FolderImgCovers
                           where fol.AccountID == accountID
                           orderby fol.FolderID descending
                           select fol;
                return item.Count() > 0 ? item.FirstOrDefault() : null;
            }
        }

        public Guid SaveFolderImgCover(FolderImgCover folder)
        {
            Guid result;
            using (MXHEntities context = conn.GetContext())
            {
                context.FolderImgCovers.AddObject(folder);
                context.SaveChanges();
                result = folder.FolderID;
            }
            return result;
        }
    }
}
